package cn.yunhe.hui.service.impl;

import cn.yunhe.hui.entity.User;
import cn.yunhe.hui.mapper.Usermapper;
import cn.yunhe.hui.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private Usermapper usermapper;

    @Override
    public Page<User> getUserByPage(int pageNum, int pageSize, User user) {
        Page<User> page = new Page<User>(pageNum, pageSize);
        page = (Page<User>) usermapper.selectPage(page, new QueryWrapper<User>().like("username", user.getUsername()).orderByDesc("id"));
        return page;

    }

    @Override
    public Page<User> getVipByPage(int pageNum, int pageSize, User user) {
        Page<User> page = new Page<User>(pageNum, pageSize);
        page = (Page<User>) usermapper.selectPage(page, new QueryWrapper<User>().like("username", user.getUsername()));
        return page;
    }

    @Override
    public int updateById(User user) {
        return usermapper.updateById(user);
    }

    @Override
    public int selectCount() {
        return usermapper.selectCount(new QueryWrapper<User>().eq("state", "0"));
    }
}
